package com.klikmee.sms.chat.web.listeners;

import java.util.Observable;
import java.util.Observer;

import org.apache.log4j.Logger;

import com.klikmee.sms.cef.bulk.BulkSender;
import com.klikmee.sms.services.chat.model.Question;

/**
 * This class can be registered to listen for new request messages event. When
 * invoked it will send canned info the the user via bulk provider.
 * 
 * @author makcro
 */
public class CannedInfoBulkSenderImpl implements Observer {

	/**
	 * Instance of the logger
	 */
	private Logger logger = Logger.getLogger(CannedInfoBulkSenderImpl.class);
	/**
	 * Text of the canned response
	 */
	private String cannedResponseText = null;

	/**
	 * Bulk sender instance used to send bulk message
	 */
	private BulkSender bulkSender = null;
	/**
	 * Invoked when new request message is received by service.
	 * 
	 * @param arg
	 *            this will be the actual {@link Question} instance received.
	 * 
	 */
	@Override
	public void update(Observable o, Object arg) {
		// check for the type of the event argument.
		if (!(arg instanceof Question)) {
			logger.fatal(String.format("Event argument is not of the expected type %s", Question.class.getCanonicalName()));
			return;
		}
		Question question = (Question) arg;
		
		logger.info(String.format("info message sent to customer for request id = %s", question.getCoreID()));
	}

	public void setCannedResponseText(String cannedResponseText) {
		this.cannedResponseText = cannedResponseText;
	}

}
